<template>
	<div class="add_container">
		<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">

			<el-form-item label="生日" required>
				<el-col :span="11">
					<el-form-item prop="date">
						<el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.birthday" style="width: 100%;"></el-date-picker>
					</el-form-item>
					

				</el-col>
			</el-form-item>

			<el-form-item label="姓名" prop="name">
				<el-input v-model="ruleForm.name"></el-input>
			</el-form-item>

			<el-form-item label="省份" prop="prov">
				<el-input v-model="ruleForm.prov"></el-input>
			</el-form-item>

			<el-form-item label="城市" prop="city">
				<el-input v-model="ruleForm.city"></el-input>
			</el-form-item>
			<el-form-item label="地址" prop="address">
				<el-input v-model="ruleForm.address"></el-input>
			</el-form-item>
			<el-form-item label="邮政编码" prop="expressid">
				<el-input v-model="ruleForm.expressid"></el-input>
			</el-form-item>




			<el-form-item>
				<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
				<el-button @click="resetForm('ruleForm')">重置</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>

<script>
	export default {
		name: 'add',
		data() {
			return {
				ruleForm: {
					name: '',
					birthday: '',
					prov: '',
					city: '',
					address: '',
					expressid: ''

				},
				rules: {
					// type: 'date',
					birthday: [{
						required: true,
						type: 'date',
						message: '请选择日期',
						trigger: 'change'
					}],
					name: [{
							required: true,
							message: '请输入姓名',
							trigger: 'blur'
						},
						{
							min: 2,
							max: 15,
							message: '长度在 2 到 15 个字符',
							trigger: 'blur'
						}
					],
					prov: [{
							required: true,
							message: '请输入省份',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 15,
							message: '长度在 3 到 15 个字符',
							trigger: 'blur'
						}
					],
					city: [{
							required: true,
							message: '请输入城市',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 15,
							message: '长度在 3 到 15 个字符',
							trigger: 'blur'
						}
					],
					address: [{
							required: true,
							message: '请输入地址',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 15,
							message: '长度在 3 到 15 个字符',
							trigger: 'blur'
						}
					],
					expressid: [{
							required: true,
							message: '请输入活动名称',
							trigger: 'blur'
						},
						{
							min: 6,
							max: 6,
							message: '长度为  6 个字符',
							trigger: 'blur'
						}
					]

				}
			};
		},
		methods: {
			submitForm(ruleForm) {
				this.$refs[ruleForm].validate((valid) => {
					if (valid) {
						// 添加学生信息
						console.log(this.ruleForm)
						let res = this.$http.post("http://localhost:3000/add", this.ruleForm);
						alert('submit!');
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			resetForm(formName) {
				this.$refs[formName].resetFields();
			}
		}
	}
</script>

<style>
	.add_container {
		margin-top: 10%;
		width: 40%;
	}
</style>
